
import { ChangeEvent, useEffect, useState } from 'react'
import { Input, Space, Button, message } from 'antd';
import styles from "./register.module.scss"
import { RegisterAPI } from '@/request/api';
import { useNavigate } from 'react-router-dom';
export default function Register() {
  const NavigateTo = useNavigate();
  useEffect(() => {

  }, []);

  const [userNameVal, setUserNameval] = useState('');
  const [passWordVal, setPassWordval] = useState('');
  const [checkPassWordVal, setCheckPassWordval] = useState('');
  const userNameChange = (e: ChangeEvent<HTMLInputElement>) => {
    // 获取用户输入内容
    setUserNameval(e.target.value);
  };
  const passWordChange = (e: ChangeEvent<HTMLInputElement>) => {
    setPassWordval(e.target.value);
  }
  const checkPassWordChange = (e: ChangeEvent<HTMLInputElement>) => {
    setCheckPassWordval(e.target.value);
  }
  const submitLogin = async () => {
    if (!userNameVal.trim() || !passWordVal.trim()) {
      return alert('请输入完整信息');
    }
    let RegisterRes = await RegisterAPI({
      name: userNameVal,
      password: passWordVal
    })
    // console.log(RegisterRes);

    if (RegisterRes.code === 200) {
      message.error('注册成功');
      NavigateTo('/login');
      // window.localStorage.setItem('token', RegisterRes.token);
    } else {
      message.error(RegisterRes.message)
    }
    // NavigateTo('/page1');

  }
  return (
    <div className={styles.loginPage}>
      <div className={styles.loginBox}>
        <div>Register</div>

        <div className="form">
          <Space direction="vertical" size="middle" >
            <Input placeholder="用户名" onChange={userNameChange} />
            <Input.Password placeholder="密码" onChange={passWordChange} />
            {/* <Input.Password placeholder="确认密码" onChange={checkPassWordChange}/> */}
            <Button type="primary" block onClick={submitLogin}>Primary</Button>

          </Space>


        </div>
      </div>
    </div>
  )
}
